"""公共变量"""
import manager.config.Base_File_Config as fileConfig
from manager.tool.ApiTool import ApiTool

buildEnvironmentVariable = ApiTool.buildEnvironmentVariable

cloud_app_host = app_host = fileConfig.APP_REQUEST_HOST
device_host = fileConfig.DEVICE_REQUEST_HOST
# 2. 请求信息头
headers = {
    "X-Ca-Secversion": "1.0",
    "X-Ca-Key": fileConfig.SIGN_KEY
}

# 密钥
secret = fileConfig.SIGN_SECRET

'''

'''


# 定义请求类型 写入请求头
#
# @Param    context_type      请求报文类型
# @return    写入head
def add_request_context(context_type):
    context_type = str(context_type).lower()
    headers['Pc-Mac'] = 'Python'
    if context_type == 'form':
        headers['Content-Type'] = 'application/x-www-form-urlencoded; charset=UTF-8'
    if context_type == 'json':
        headers['Content-Type'] = 'application/json; charset=UTF-8'
    if context_type == 'file':
        headers['Content-Type'] = 'multipart/form-data; charset=UTF-8'


# 获取公共token 写入请求头，参数
#
# @Param(无参默认 否)     friend      是否好友登录 True:是，False否
# @return    Void
def getCommonTokenWriteRequestHead(**kwargs):
    # 构建操作环境变量对象
    p = buildEnvironmentVariable()
    token = p.get('token')
    if len(kwargs.items()) > 0 and kwargs.get('friend'):
        token = p.get('friendToken')
    headers['Auth-Token'] = token


# 获取指定类中所有 自定义函数
def api_init_fun(class_name):
    function_list = dir(class_name)
    api_list = []
    for i in function_list:
        if 'api_' in i:
            api_list.append(i)
    # print(f'Api 统计 ==== {class_name} 模块共有 {len(api_list)} 个接口')
